
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tathata.Common.BLL.Entities;
using Tathata.Common.BLL.Managers;
using Tathata.Common.Utils;

namespace Tathata.Web.Administration
{
    public partial class Administration_SettingDetails : BaseNopAdministrationPage
    {
        private void BindData()
        {
            Setting setting = SettingManager.GetBySettingID(this.SettingID);
            if (setting != null)
            {
                this.txtName.Text = setting.Name;
                this.txtValue.Text = setting.Value;
                this.txtDescription.Text = setting.Description;
            }
            else
                Response.Redirect("Settings.aspx");
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.BindData();
            }
        }

        protected void SaveButton_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    Setting setting = SettingManager.SetParam(txtName.Text, txtValue.Text, txtDescription.Text);
                    Response.Redirect("Settings.aspx");
                }
                catch (Exception exc)
                {
                    ProcessException(exc);
                }
            }
        }

        protected void DeleteButton_Click(object sender, EventArgs e)
        {
            try
            {
                SettingManager.DeleteSetting(this.SettingID);
                Response.Redirect("Settings.aspx");
            }
            catch (Exception exc)
            {
                ProcessException(exc);
            }
        }

        public int SettingID
        {
            get
            {
                return CommonHelper.QueryStringInt("SettingID");
            }
        }
    }
}
